import { useTokenStore } from '@/store/token.js';
const tokenStore = useTokenStore()

const BASE_URL_2 = 'http://localhost:8080'

// 发送消息给AI
export const sendMessageService = async (data, chatId) => {
  const url = new URL(`${BASE_URL_2}/api/user/ai/chat4Stream`)
  if (chatId) {
    url.searchParams.append('chatId', chatId)
  }

  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'token': tokenStore.token ? tokenStore.token : null
    },
    body: data,
    mode: 'cors'
  })

  return response.body.getReader()
}
